package test;
import java.util.ArrayList;
import java.util.Scanner;

import dao.CourseDao;
import dao.ScoreDao;
import dao.StudentDao;
import model.Course;
import model.Student;
import util.PrintUtil;



public class task {   
	private static ArrayList<Student> studentList = new ArrayList<>();
	static boolean isShowMenu = false;
	
	public static void main(String[] args) {
	    	showMenu();
	    }	

	   //查看学生数据
		private static void showMenu(){

			while(true) {
				//为了避免程序疯狂运行导致死机,每秒钟检查一次是否展开菜单
				try {
					Thread.sleep(1000);
				}catch(InterruptedException e){
					e.printStackTrace();
				}
				
				if(!isShowMenu) {
					PrintUtil.showMenu();
					isShowMenu = true;
					
					Scanner sc = new Scanner(System.in);
					int i;
					try {
						i = sc.nextInt();
						
						switch(i) {
						case 1:
							studentList = StudentDao.queryStudentList();
							PrintUtil.display(studentList);
							break;
						case 2:
							Student student = getStudentInfo();
							StudentDao.addUseStatement(student);
							
							break;
						case 3:
							//获取用户输入的学生姓名
							String name = getStudentName();
							//对用户输入的学生进行删除
							StudentDao.del(name);
							break;
						case 4:
							//获取要修改的学生的信息
							String studname = getStudentName();
							//获取要修改的字段
							int column = getUpdateColum();
							//获取要修改的值
							Object value = getNewValue();
							//更新学生表
							StudentDao.update(studname,column,value);
							break;
						case 5:
							//获取要修改的学生信息
							String stu_name = getStudentName();
							//通过学生姓名获取ID
							//int stu_id = StudentDao.getStuIdWithName(Stu_name);
							//通过CourseDao获取课程列表
							ArrayList<Course> courseList = CourseDao.queryCourseList();
							//打印课程列表
							PrintUtil.printCourse(courseList);
							//获取学生的选课成绩
							int score = getCourseScore();
							//插入选课和成绩
							//
							break;
						case 6:
							System.exit(0);
							break;
						default:
					        System.out.println("输入有误！");
							break;
						}
					}catch(Exception e) {
						System.out.println("输入有误！");
					}
					isShowMenu = false;
				}
			}
		}


        //获取学生信息
		private static Student getStudentInfo() {
        	Scanner in = new Scanner(System.in);
    		System.out.println("请输入学号");
    		int stuid = in.nextInt();
    		
    		in = new Scanner(System.in);
    		System.out.println("请输入姓名");
    		String name = in.nextLine();
    		
    		in = new Scanner(System.in);
    		System.out.println("请输入性别");
    		String gender = in.nextLine();
    		
    		in = new Scanner(System.in);
    		System.out.println("请输入年龄");
    		int age = in.nextInt();
    		
    		in = new Scanner(System.in);
    		System.out.println("请输入班级");
    		String class_name = in.nextLine();
   	
    		in = new Scanner(System.in);
    		System.out.println("请输入专业");
    		String majorname = in.nextLine();
    		
    		
    		System.out.println("学生信息输入完成");
    		
    		Student student = new Student(stuid, name, gender, age ,  class_name,  majorname);
    				return student;
        }
		
		//获取学生姓名
        private static String getStudentName() {
        	System.out.println("请输入你要操作的学生的名字:");
    		Scanner input = new Scanner(System.in);
    		String name = input.nextLine();
		return name;
	}
       
        //输入要删除的列
        private static int getUpdateColum() {
        	Scanner input = new Scanner(System.in);
        	System.out.println("请选择要更新的字段:");
        	System.out.println("1.学号");
        	System.out.println("2.姓名");
        	System.out.println("3.性别");
        	System.out.println("4.年龄");
        	System.out.println("5.班级");
        	System.out.println("6.专业");
        	
        	int result = input.nextInt();
        	return result;
        }
        
        //输入要更新的值
        private static Object getNewValue() {
        	Scanner input = new Scanner(System.in);
        	System.out.println("请输入新的值：");
        	Object value= input.next();
        	return value;
        }
        
        private static int getCourseScore() {
        	Scanner in = new Scanner(System.in);
        	System.out.println("请输入课程成绩");
        	int value =in.nextInt();
        	return value;
        }
        
        private static int getSeletedCourseId() {
        	Scanner in = new Scanner(System.in);
        	System.out.println("请输入课程ID");
        	int value = in.nextInt();
        	return value;
        }
}
  
	


